<template>
  <div>
    <puplic-modal
      width="980px"
      :publicVisible="publicVisible"
      modalStyle="addEditSupportModal"
      @cancel="cancel"
      @handleOk="handleOk"
      :title="title"
    >
      <div slot="content" class="content">
        <div class="search-group flex">
          <div class="input-wrap f1">
            <div class="label">类别名称:</div>
            <div class="input-item" style="width: 100%">
              <j-input
                clearable
                :maxLength="30"
                placeholder="请输入类别名称"
                v-model="queryParam.examineCategoryName"
              />
            </div>
          </div>

          <div class="btn-wrap">
            <a-button class="searchBtn" @click="searchQuery()" type="primary"> 搜索 </a-button>
            <a-button class="resetBtn" @click="searchReset()" type="primary"> 重置 </a-button>
          </div>

          <div class="btn f1" style="text-align: right">
            <a-button class="searchBtn" @click="addEditHandle()" type="primary"> 新增 </a-button>
          </div>
        </div>

        <div class="f1">
          <a-table
            rowKey="id"
            class="tableList"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            @change="handleTableChange"
          >
            <template slot="title" slot-scope="records">
              <a-tooltip placement="top">
                <template slot="title">
                  <span>{{ records.title }} </span>
                </template>
                <span>{{ records.title }} </span>
              </a-tooltip>
            </template>
            <template slot="action" slot-scope="records">
              <!-- <span class="operation deatil-color" @click="addEditHandle(records)">编辑</span> -->
              <span class="operation warnColor" @click="showDelete(records)">删除</span>
            </template>
          </a-table>
        </div>
      </div>
      <div slot="footer"></div>
    </puplic-modal>
    <allMessage
      ref="allMessage"
      :publicVisible="deleteVisible"
      @cancel="deleteVisible = false"
      @tipMessage="tipMessage"
    ></allMessage>
    <category-add ref="categoryAdd" @refresh="searchQuery()"></category-add>
  </div>
</template>
<script>
import categoryAdd from './categoryAdd'
import allMessage from '@/components/allMessage'
import puplicModal from '@/components/publicModal'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { examineCategoryDelete } from '@/api/industry'
import JInput from '@/components/jeecg/JInput'
export default {
  components: { puplicModal, allMessage, categoryAdd, JInput },
  mixins: [JeecgListMixin],
  name: 'addEditSupportModal',
  data() {
    return {
      url: {
        list: '/industry/examine_category/page',
      },
      title: '新增',
      publicVisible: false,
      deleteVisible: false,
      disableMixinCreated: true,
      queryParam: {},
      records: {},
      isorter: {
        column: 'categoryNo',
        order: 'asc',
      },
      columns: [
        {
          title: '序号',
          align: 'center',
          width: 100,
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '类别名称',
          dataIndex: 'examineCategoryName',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '排序值',
          dataIndex: 'categoryNo',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '添加人',
          dataIndex: 'createBy',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '操作',
          scopedSlots: { customRender: 'action' },
          ellipsis: true,
          align: 'center',
        },
      ],
    }
  },
  methods: {
    show(records) {
      this.records = records
      this.queryParam.industryExamineId = records.id
      this.title = records.industryExamineName + '-检查类别'
      this.loadData()
      this.publicVisible = true
    },
    searchReset() {
      if (this.queryParam.industryExamineId) {
        let id = this.queryParam.industryExamineId
        this.queryParam = {}
        this.queryParam.industryExamineId = id
      } else {
        this.queryParam = {}
      }
      this.resetTime = true
      this.loadData(1)
    },

    handleOk() {
      this.publicVisible = false
      this.$emit('refresh')
    },
    cancel() {
      this.publicVisible = false
      this.$emit('refresh')
    },

    addEditHandle() {
      this.$refs.categoryAdd.show(this.records)
    },

    showDelete(records) {
      this.deleteVisible = true
      this.$refs.allMessage.show(records)
    },

    tipMessage(records) {
      examineCategoryDelete({ id: records.id }).then((res) => {
        this.$message.success(res.message)
        this.deleteVisible = false
        this.searchQuery()
      })
    },
  },
}
</script>
<style scoped lang="less">
@import '~@/assets/less/common.less';

/deep/ .content {
  padding: 20px;
}

/deep/ .modalFooter {
  height: 0 !important;
}

.search-group {
  padding: 0;
}
</style>
